/* Author: David McCoy dave.mccoy@cospandesign.com
 *
 *     This file is part of DLCM\SubServ.
 *
 *  DLCM\SubServ is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  DLCM\SubServ is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with DLCM\SubServ.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * TCPGuiProvider.java
 *
 * User interface portion of a TCP provider setup
 *
 * Created on Mar 21, 2010, 10:01:55 PM
 */

package com.cospandesign.gui.providers.tcp;

import com.cospandesign.gui.providers.ProviderGeneratorInterface;
import java.net.SocketException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TCPGuiProvider extends javax.swing.JPanel implements ProviderGeneratorInterface{

    /** Creates new form UDPGuiProvider */
    public TCPGuiProvider(){
        initComponents();
        try {
            this.networkInterfacePanel.ReloadTree();
        } catch (SocketException ex) {
            Logger.getLogger(TCPGuiProvider.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    
    // <editor-fold defaultstate="collapsed" desc="ProviderGeneratorInterface Methods">
    public String getProviderName() {
        return "TCP";
    }

    public HashMap<String, String> getProviderVariables() {
        tCPGenerator.setNetworkName(this.networkInterfacePanel.IP1TextBox.getText() + "." + this.networkInterfacePanel.IP2TextBox.getText() + "." + this.networkInterfacePanel.IP3TextBox.getText() + "." + this.networkInterfacePanel.IP4TextBox.getText());
        return tCPGenerator.getProviderVariables();
    }// </editor-fold>

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tCPGenerator = new com.cospandesign.gui.providers.tcp.TCPGenerator();
        PortFormatedText = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        try {
            networkInterfacePanel = new com.cospandesign.gui.providers.NetworkInterfacePanel();
        } catch (java.net.SocketException e1) {
            e1.printStackTrace();
        }

        setMaximumSize(new java.awt.Dimension(150, 220));
        setName("TCP"); // NOI18N
        setPreferredSize(new java.awt.Dimension(150, 220));

        PortFormatedText.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#"))));
        PortFormatedText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        PortFormatedText.setText("7600");
        PortFormatedText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                PortFormatedTextFocusLost(evt);
            }
        });
        PortFormatedText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                PortFormatedTextKeyPressed(evt);
            }
        });

        jLabel2.setText("Port");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PortFormatedText, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(networkInterfacePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(networkInterfacePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PortFormatedText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void PortFormatedTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_PortFormatedTextKeyPressed
        tCPGenerator.setPortNumber(PortFormatedText.getText());
    }//GEN-LAST:event_PortFormatedTextKeyPressed

    private void PortFormatedTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_PortFormatedTextFocusLost
        tCPGenerator.setPortNumber(PortFormatedText.getText());
    }//GEN-LAST:event_PortFormatedTextFocusLost

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField PortFormatedText;
    private javax.swing.JLabel jLabel2;
    private com.cospandesign.gui.providers.NetworkInterfacePanel networkInterfacePanel;
    private com.cospandesign.gui.providers.tcp.TCPGenerator tCPGenerator;
    // End of variables declaration//GEN-END:variables


}
